package top.lingkang.websocketlivechrome.nt;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.FullHttpRequest;

/**
 * @Author 绫小路
 * @Date 2021/2/10
 * 在此处鉴权处理
 * 链接websocket将提升成websocket协议前调用
 */
public class MyWebsocketAuthHandler extends SimpleChannelInboundHandler<FullHttpRequest> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
        System.out.println("请求的路径：" + msg.uri());

        //url 鉴权
        /*if (msg.uri().indexOf("zhangsan") == -1) {
            //直接关闭channel
            if (ctx.channel().isActive()) {
                ctx.channel().writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
            }
        }*/

        //放行，给下一个handler处理 此处关键
        ctx.fireChannelRead(msg.retain());
    }

}
